//
//  accountDetailTableViewCell.m
//  SoundPill
//
//  Created by 宋旭东 on 16/2/23.
//  Copyright © 2016年 宋旭东. All rights reserved.
//

#import "accountDetailTableViewCell.h"
#import "UIViewExt.h"
//#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#define kleftGap  10
#define kupGap   12
#define kDeviceWidth [UIScreen mainScreen].bounds.size.width
#define kImageViewWidth 40
#define kImageViewHeight 40
#define kLabelWidth [UIScreen mainScreen].bounds.size.width*0.35
#define kLabelHeight 60

@interface accountDetailTableViewCell ()
{
    UIImageView *downDivider;
}
@end

@implementation accountDetailTableViewCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
        //self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.backgroundColor=[UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
}
- (void)initSubViews
{
    // 图片
    self.avatar = [[UIButton alloc] initWithFrame:CGRectZero];
    _avatar.userInteractionEnabled = NO;
    [self addSubview:_avatar];
    
    self.username = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_username];
    
    self.date = [[UILabel alloc] initWithFrame:CGRectZero];
    [self addSubview:_date];
    
    // 描述
    self.detaillable = [[UILabel alloc] initWithFrame:CGRectZero];
    _detaillable.backgroundColor = [UIColor whiteColor];
//    _detaillable.font = [UIFont boldSystemFontOfSize:16];
//    _detaillable.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_detaillable];
    
    self.cashLable = [[UILabel alloc] initWithFrame:CGRectZero];
    _cashLable.backgroundColor = [UIColor whiteColor];
    [self addSubview:_cashLable];
    
    downDivider = [[UIImageView alloc] initWithFrame:CGRectMake(3, 58.6, kDeviceWidth-6, 0.8)];
    [self addSubview:downDivider];

}
- (void)layoutSubviews
{
    [super layoutSubviews];
    //首图预览
    _avatar.frame = CGRectMake(kleftGap, kupGap, self.height - (2 * kupGap), self.height - (2 * kupGap));
    _avatar.backgroundColor=[UIColor whiteColor];
    
    [_avatar setBackgroundImageWithURL:[NSURL URLWithString:self.model.avatar] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"default_head"]];
    
    //分隔线
    downDivider.frame = CGRectMake(0, self.height, kDeviceWidth, 0.5);
    downDivider.backgroundColor = [UIColor colorWithRed:0.895 green:0.898 blue:0.908 alpha:1.000];

    _username.frame = CGRectMake(_avatar.right + 10, _avatar.top + 1, self.frame.size.width - (_avatar.right + 10), _avatar.height / 2);
    _username.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    _username.textColor = [UIColor blackColor];
    _username.text = _model.username;
//    NSLog(@"%@",_username);

    _date.frame = CGRectMake(_avatar.right + 10, _username.top,  self.frame.size.width - (_avatar.right + 20), _avatar.height / 2);
    _date.text = _model.datetime;
    _date.font = [UIFont systemFontOfSize:13];
    _date.textAlignment = NSTextAlignmentRight;
    _date.textColor = [UIColor colorWithRed:0.717 green:0.719 blue:0.727 alpha:1.000];

    _detaillable.textColor = [UIColor grayColor];
    _detaillable.font = [UIFont systemFontOfSize:14];
    _detaillable.text = [NSString stringWithFormat:@"向你的作品 %@", _model.title];
    _detaillable.frame = CGRectMake(_avatar.right + 10, self.height - 16 - kupGap,(self.frame.size.width - (_avatar.right + 10)) / 2, 16);
//    NSLog(@"%@",_detaillable);
    
    _cashLable.textColor = [UIColor grayColor];
    _cashLable.font = [UIFont systemFontOfSize:14];
    _cashLable.text = [NSString stringWithFormat:@"支付 ¥%@", _model.cash];
    _cashLable.frame = CGRectMake(_detaillable.right + 5, _detaillable.top, _detaillable.width, _detaillable.height);
}

- (CGSize)boundingRectWithSize:(CGSize)size text:(NSString *)text font:(UIFont *)font
{
    NSDictionary *attribute = @{NSFontAttributeName: font};
    
    CGSize retSize = [text boundingRectWithSize:size
                                        options:\
                      NSStringDrawingTruncatesLastVisibleLine |
                      NSStringDrawingUsesLineFragmentOrigin |
                      NSStringDrawingUsesFontLeading
                                     attributes:attribute
                                        context:nil].size;
    
    return retSize;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
